package top.datacluster.basic.algorithm.leetcode.stack;

import java.util.Stack;

public class LeetCode1435 {

    public static void main(String[] args) {
        MinStack1 minStack1 = new MinStack1();
        minStack1.push(-2);
        minStack1.push(0);

        minStack1.push(-3);
        System.out.println(minStack1.getMin());
        minStack1.pop();
        System.out.println(minStack1.top());
        System.out.println(minStack1.getMin());

    }
}

class MinStack1 {

    public Stack<Integer> stack = new Stack<>();

    public Stack<Integer> min = new Stack<>();

    /** initialize your data structure here. */
    public MinStack1() {

    }

    public void push(int x) {
        stack.push(x);
        if (min.isEmpty()){
            min.push(x);
        }else if (min.peek() >= x){
            min.push(x);
        }else{
            min.push(min.peek());
        }
    }

    public void pop() {
        stack.pop();
        min.pop();
    }

    public int top() {
        return stack.peek();
    }

    public int getMin() {
        return min.peek();
    }
}